package net.ericaro.neojavagengen;

import net.ericaro.neojavagen.Literals;
import net.ericaro.neojavagen.classes.InterfaceTypes;
import net.ericaro.neojavagen.names.QualifiedIdentifier;
import net.ericaro.neojavagen.packages.CompilationUnit;
import net.ericaro.neojavagen.types.ClassOrInterfaceType;
import net.ericaro.neojavagen.types.Identifier;
import net.ericaro.neojavagen.types.InterfaceType;
import net.ericaro.neojavagen.types.Type;
import net.ericaro.neojavagen.types.TypedIdentifier;




public class PartReference {

	Part part;
	//String name;
	Grammar grammar;
	
	private boolean resolved;

	public PartReference(Grammar g, String name) {
		super();
		this.grammar = g;
	}
	
	public PartReference(Grammar g, Identifier simpleTypeName, TypedIdentifier nameIdentifier) {
		super();

		
		this.grammar = g;
	}
	
	public void attach(Part impl){
		assert this.part == null : "it's a mistake to attach a part to an already attached PartReference";
		this.part = impl;
	}

	public Identifier getSimpleTypeName() {
		checkResolved();
		return part.getSimpleTypeName();
	}

	private void checkResolved() {
		if (!resolved) {
			resolved = true;
			part.resolve();
		}
	}

	public ClassOrInterfaceType getClassOrInterfaceType() {
		checkResolved();
		return part.getClassOrInterfaceType();
	}

	public Part get() {
		return part;
	}

	public void addInterfaceType(ClassOrInterfaceType classOrInterfaceType) {
		checkResolved();
		part.addInterfaceType(classOrInterfaceType);
		
	}

	public CompilationUnit getCompilationUnit() {
		checkResolved();
		return part.getCompilationUnit();
	}

	public void resolve() {
		checkResolved();
		
	}
	
}
